package com.mmc.delay.controller;

import com.mmc.delay.api.JobHandle;
import com.mmc.delay.api.Producer;
import com.mmc.delay.bean.Job;
import com.mmc.delay.bean.JobParam;
import com.mmc.delay.enums.TopicEnum;
import com.mmc.delay.factory.DelayFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

  @Autowired
  private Producer producer;


    @RequestMapping("/testMessage")
    public String test(){
        JobParam jobParam=new JobParam();
        jobParam.setBody("aaa");
        jobParam.setJobId("1");
        jobParam.setTopic(TopicEnum.ORDER.name());
        producer.syncPutMessage(jobParam);
        return "success";
    }

    @RequestMapping("/testDelay")
    public String testDelay(String id, @RequestParam(required = false) Long delayTime, String topic){
        JobParam jobParam=new JobParam();
        jobParam.setBody("");
        jobParam.setJobId(id);
        jobParam.setTopic(topic);
        jobParam.setDelayTime(delayTime==null?0:delayTime);
        jobParam.setRetries(5);
        producer.syncPutMessage(jobParam);
        return "success";
    }



    @RequestMapping("/exit")
    public String exit(){
        System.exit(-1);
        return "";
    }




}
